﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DEMO_TEMP1
{

    public partial class Form4 : Form
    {
        WebPor.Service1 lc = new WebPor.Service1();
            
        DataSet ds_search = new DataSet();
        DataSet ds_location = new DataSet();
        string userid,mawb= "";
        int index4 = 0;

        public Form4(string user,DataSet ds_s, int index)
        {
            lc.Url = string.Format("http://192.168.1.220/WebAppPor01/Service1.asmx");
           // ds_location = lc.GetLocationHis(mawb_no);
             InitializeComponent();
             userid = user;
             if (ds_s == null)
            {
                MessageBox.Show("data error");
            }
            else
            {
                ds_search = ds_s;
                ds_location = ds_s;
                index4 = index;
                mawb = ds_search.Tables[0].Rows[index4]["display_mawb"].ToString();
                ds_search = lc.GetInventoryDetail(mawb);
                setdata(ds_search);
            }
            
        }

        private void setdata(DataSet ds)
        {
         
            DataTable T_Loc = CreateTableLoc(ds_search);
            dataGrid1.DataSource = T_Loc;
               
        }
        private DataTable CreateTableLoc(DataSet ds)
        {
            string time;
            string loc, sin, sout;
            DataTable MAWB_list = new DataTable();
            MAWB_list.Columns.Add("Time", typeof(DateTime));
            MAWB_list.Columns.Add("Loc", typeof(string));
            MAWB_list.Columns.Add("in", typeof(string));
            MAWB_list.Columns.Add("out", typeof(string));
            ////////////////////Getdata form dataset//////////////////////////
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
               // time = ds.Tables[0].Rows[i]["display_flight_date"].ToString().Trim();
                time = ds.Tables[0].Rows[i]["display_flight_date"].ToString().Trim(); ;
                loc = ds.Tables[0].Rows[i]["location"].ToString().Trim();
                sin = ds.Tables[0].Rows[i]["piece_count"].ToString().Trim();
                sout = ds.Tables[0].Rows[i]["piece_count"].ToString().Trim();
                MAWB_list.Rows.Add(time, loc, sin, sout);
            }
            //string t = ds.Tables[0].Rows[0]["time"].ToString().Trim();
            
            
            /////////////////////////////////////////////////////////////////
            

            //////////////set size Table////////////////////////////////////

            ////////////////////////////////////////////////////////////////
            return MAWB_list;
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            //mawb = ds_search.Tables[0].Rows[index4]["display_mawb"].ToString();
            Form3 f3 = new Form3(userid, ds_location, mawb);
            f3.Show();
        }
        DataSet redata = new DataSet();
        private void menuItem2_Click(object sender, EventArgs e)
        {

       
            Retrieval.TempConF tempf = new DEMO_TEMP1.Retrieval.TempConF(userid,ds_search,index4);
            tempf.Show();
            this.Close();

        }

        private void Form4_Load(object sender, EventArgs e)
        {
            
        }

        private void dataGrid1_Click(object sender, EventArgs e)
        {
            dataGrid1.Select(dataGrid1.CurrentRowIndex);
            string m = string.Empty;
            m = dataGrid1.CurrentRowIndex.ToString();
            
            int m2 = int.Parse(m);
            index4 = m2;

        }

        private void dataGrid1_DoubleClick(object sender, EventArgs e)
        {
            dataGrid1.UnSelect(dataGrid1.CurrentRowIndex);
        }

    }
}